package com.hengpeng.msls.tools;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 线程池服务类
 * 
 * @author weiyuan
 */
public class PoolServer {

    public static Log logger = LogFactory.getLog(PoolServer.class);

    private ThreadPoolExecutor executor;// 创建线程执行器

    public PoolServer(int poolSize) {
        /**
         * 创建一个固定数量的线程池
         */
        this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(poolSize);
    }

    /**
     * 添加任务
     * 
     * @param task
     */
    public void executeTask(Runnable runnable) {
        this.executor.execute(runnable);
    }

    /**
     * 结束
     */
    public void endServer() {
        this.executor.shutdown();
    }
}
